﻿#include "FilterRecordOfCharge.h"
#include "ui_filterrecordofcharge.h"

FilterRecordOfCharge::FilterRecordOfCharge(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::FilterRecordOfCharge)
{
    ui->setupUi(this);
    time = new QLabel(ui->frameBottom);
    time->setGeometry(10, 10, 200, 40);
    time->setStyleSheet("QLabel{font: 20px; color: rgb(25, 25, 112);}");
    signal = new QLabel(ui->frameBottom);
    signal->setGeometry(700, 18, 41, 22);
    signal->setStyleSheet("QLabel{background-color:transparent;}");

    QDir dir(IMAGE_PATH);
    if(dir.exists())
    {
        ui->frameTop->setStyleSheet(LOGO_STY);
    }

    QRegExp dateTimeRegExp("(([1-9])\\d)-((0[1-9])|(1[0-2]))\\-((0[1-9])|([1-2]\\d)|(3[0-1]))");
    QValidator* validatorDateTime = new QRegExpValidator(dateTimeRegExp, 0);

    ui->m_editChargeRecordFilter_StartTime->setValidator(validatorDateTime);
    ui->m_editChargeRecordFilter_EndTime->setValidator(validatorDateTime);

    keyBoardConnect();

}


void FilterRecordOfCharge::on_Keyboard_clicked()
{
    QPushButton* btn =  static_cast<QPushButton*>(sender());

    QLineEdit* focus = (QLineEdit* )QApplication::focusWidget();

    keyHandle(btn, focus);

}

void FilterRecordOfCharge::keyHandle(QPushButton* btn, QLineEdit* lineEdit)
{
    if( btn->text() == tr("空格") )
    {
        lineEdit->insert(" ");
    }
    else if( btn->text() == tr("退格") )
    {
        lineEdit->backspace();
    }
    else if( btn->text() == tr("清除"))
    {
        lineEdit->clear();
    }
    else
    {
        lineEdit->insert(btn->text());
    }
}

void FilterRecordOfCharge::keyBoardConnect()
{
    connect(ui->One, SIGNAL(clicked()), this, SLOT(on_Keyboard_clicked()));
    connect(ui->Tow, SIGNAL(clicked()), this, SLOT(on_Keyboard_clicked()));
    connect(ui->Three, SIGNAL(clicked()), this, SLOT(on_Keyboard_clicked()));
    connect(ui->Four, SIGNAL(clicked()), this, SLOT(on_Keyboard_clicked()));
    connect(ui->Five, SIGNAL(clicked()), this, SLOT(on_Keyboard_clicked()));
    connect(ui->Six, SIGNAL(clicked()), this, SLOT(on_Keyboard_clicked()));
    connect(ui->Seven, SIGNAL(clicked()), this, SLOT(on_Keyboard_clicked()));
    connect(ui->Eight, SIGNAL(clicked()), this, SLOT(on_Keyboard_clicked()));
    connect(ui->Nine, SIGNAL(clicked()), this, SLOT(on_Keyboard_clicked()));
    connect(ui->Zero, SIGNAL(clicked()), this, SLOT(on_Keyboard_clicked()));
    connect(ui->Remove, SIGNAL(clicked()), this, SLOT(on_Keyboard_clicked()));
    connect(ui->RemoveAll, SIGNAL(clicked()), this, SLOT(on_Keyboard_clicked()));
    connect(ui->Char1, SIGNAL(clicked()), this, SLOT(on_Keyboard_clicked()));
    connect(ui->Char2, SIGNAL(clicked()), this, SLOT(on_Keyboard_clicked()));
    connect(ui->Space, SIGNAL(clicked()), this, SLOT(on_Keyboard_clicked()));
}

void FilterRecordOfCharge::on_buttonOk_clicked()
{
    /*待完成*/
    emit onFiltrateData(1,ui->m_editChargeRecordFilter_CardNum->text().trimmed(),
                        ui->m_editChargeRecordFilter_StartTime->text().trimmed(),
                        ui->m_editChargeRecordFilter_EndTime->text().trimmed());

    ui->m_editChargeRecordFilter_CardNum->clear();
    ui->m_editChargeRecordFilter_StartTime->clear();
    ui->m_editChargeRecordFilter_EndTime->clear();
}

void FilterRecordOfCharge::on_buttonBack_clicked()
{
    stackLayout->setCurrentIndex(recordOfChargePage);
}

FilterRecordOfCharge::~FilterRecordOfCharge()
{
    delete ui;
}

